from urllib import request
import random

class Proxy():
    def __init__(self,fname):
        with open(fname,'r',encoding='utf-8') as f:
            self.proxy_list = f.readlines()

    def random_proxy(self):
        proxy = random.choice(self.proxy_list)
        proxy_info = proxy.split(',')
        host = proxy_info[0]
        port = proxy_info[1]

        proxy = {
            'http' : 'http://%s:%s' % (host,port),
            'https' : 'http://%s:%s' % (host,port)
        }
        return proxy

    def get_all_proxy(self):
        proxy_list = []
        for proxy in self.proxy_list:
            proxy_info = proxy.split(',')
            host = proxy_info[0]
            port = proxy_info[1]
            proxy = {
                'http' : 'http://%s:%s' % (host,port),
                'https' : 'http://%s:%s' % (host,port)
            }
            proxy_list.append(proxy)
        return proxy_list

if __name__ == '__main__':
    p = Proxy('66.csv')
    proxy = p.random_proxy()
    print(proxy)